﻿#ifndef APP_ANIM_H
#define APP_ANIM_H

#ifdef __cplusplus
extern "C" {
#endif

#include "app_config.h"

#define ANIM_DEF(start_time, obj, attr, start, end) \
     {start_time, obj, LV_ANIM_EXEC(attr), start, end, 500, lv_anim_path_ease_out, true}

#define ANIM_DEF_1S(start_time, obj, attr, start, end) \
     {start_time, obj, LV_ANIM_EXEC(attr), start, end, 1000, lv_anim_path_ease_out, true}

/* 页面切换类型  */
typedef enum
{
    /* Default (global) animation type  */
    LOAD_ANIM_GLOBAL = 0,

    /* New page overwrites old page  */
    LOAD_ANIM_OVER_LEFT,
    LOAD_ANIM_OVER_RIGHT,
    LOAD_ANIM_OVER_TOP,
    LOAD_ANIM_OVER_BOTTOM,

    /* New page pushes old page  */
    LOAD_ANIM_MOVE_LEFT,
    LOAD_ANIM_MOVE_RIGHT,
    LOAD_ANIM_MOVE_TOP,
    LOAD_ANIM_MOVE_BOTTOM,

    /* The new interface fades in, the old page fades out */
    LOAD_ANIM_FADE_ON,

    /* No animation */
    LOAD_ANIM_NONE,

    _LOAD_ANIM_LAST = LOAD_ANIM_NONE
} app_anim_type_e;

typedef enum
{
    ROOT_DRAG_DIR_NONE,
    ROOT_DRAG_DIR_HOR,
    ROOT_DRAG_DIR_VER,
} app_anim_drag_dir_e;

typedef struct {
    bool is_switch_req; // 是否切换页面请求
    bool is_busy;       // 是否在切换中
    bool is_pushing;    //
}app_anim_state_t;

/* Animated setter  */
typedef void(*lv_anim_setter_t)(void*, int32_t);
/* Animated getter  */
typedef int32_t(*lv_anim_getter_t)(void*);

/* Animation switching record  */
typedef struct
{
    /* As the entered party */
    struct
    {
        int32_t start;
        int32_t end;
    } enter;

    /* As the exited party */
    struct
    {
        int32_t start;
        int32_t end;
    } exit;
} app_anim_value_t;

typedef struct
{
    lv_anim_setter_t setter;
    lv_anim_getter_t getter;
    app_anim_drag_dir_e drag_dir;
    app_anim_value_t push;
    app_anim_value_t pop;
} app_anim_attr_t;

void app_anim_set_global(app_anim_type_e type, uint32_t time, lv_anim_path_cb_t path);

void app_anim_init(lv_anim_t* a, app_anim_attr_t* attr);
void app_anim_init_attr(app_anim_attr_t* attr);
app_anim_type_e app_anim_get_type();

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif
